<?php

namespace Database\Seeders;

use App\Models\CategoryModel;
use App\Models\ContentModel;
use Illuminate\Database\Seeder;

class ContentSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $contentList = [
            [
                'category' => '小游戏',
                'content' => [
                    [
                        'logo' => '/resources/static/content-jzttt.png',
                        'title' => '建造通天塔',
                        'keywords' => '建造通天塔',
                        'description' => '建造通天塔是一个很好玩的游戏',
                        'jump' => ContentModel::JUMP_TYPE_NEW,
                        'jump_link' => 'https://www.wesane.com/game/816/',
                        'sort' => 0,
                        'status' => ContentModel::STATUS_OPEN
                    ],
                    [
                        'logo' => '/resources/static/content-qchrd.jpg',
                        'title' => '汽车华容道',
                        'keywords' => '汽车华容道',
                        'description' => '汽车华容道是一个很好玩的游戏',
                        'jump' => ContentModel::JUMP_TYPE_NEW,
                        'jump_link' => 'https://www.wesane.com/game/816/',
                        'sort' => 0,
                        'status' => ContentModel::STATUS_OPEN
                    ]
                ]
            ]
        ];

        // 循环批量插入数据
        foreach ($contentList as $contentItem) {
            $categoryId = CategoryModel::query()->where('name', $contentItem['category'])->value('id');
            if (!empty($categoryId)) {
                $insertData = [];
                foreach ($contentItem['content'] as $childrenItem) {
                    $insertData[] = array_merge(['category_id' => $categoryId], $childrenItem);
                }
                if (!empty($insertData)) {
                    ContentModel::query()->insert($insertData);
                }
            }
        }
    }
}
